package com.yxym.poly.polyarr_;

public class PloyArray {
    public static void main(String[] args) {

        Person[] person = new Person[3];
        person[0] = new Person("yxym",20);
        person[1] = new Student("yamin",22,90.0);
        person[2] = new Teacher("mm",30,30000.0);

        for (int i = 0; i < person.length ; i++) {
            System.out.println(person[i].say());//动态绑定机制
            //判断类型机制，
            if (person[i] instanceof Student) {
               Student student  = (Student) person[i];
               student.work();
            }else  if (person[i] instanceof Teacher) {
                Teacher teacher = (Teacher) person[i];
                teacher.speak();
            }else if (person[i] instanceof Person) {
            }
            else {
                System.out.println("类型有误，重新输入！");
            }
        }
    }
}
